﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using JohnnySins.DAL;
using JohnnySins.DAL.Repositories;
using JohnnySins.Entities;
using JohnnySins.Code;
using System.Configuration;

namespace JohnnySins
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ConfigurationManager.AppSettings["IsDevelopmentEnvironment"] == null)
            {
                if (Session["Start"] == null)
                    Response.Redirect("~/Default.aspx");

                string urlCurrent = Request.Url.ToString().ToLower();
                if (!urlCurrent.Contains("//www."))
                {
                    string newUrl = urlCurrent.Replace("http://", "http://www.").Replace("https://", "https://www.");
                    Response.Redirect(newUrl, false);
                }
            }
            FillNextLiveShow();
            FillBanner();
            SetActiveLink();
        }

        protected void FillBanner()
        {
            using (var repo = RepositoryFactory.ResolveRepository<BannerRepository>())
            {
                string content = "";
                List<Banner> lst = repo.FindActive("Home").ToList();
                foreach(Banner item in lst)
                {
                    content += string.Format("<li><img src={0} alt=\"\"></li>", ResolveClientUrl("~/Files/ImageBanner/Home/") + item.PhysFileName);
                }
                slider1.InnerHtml = content;
            }
           
        }

        protected void FillNextLiveShow()
        {
            using (var repo = RepositoryFactory.ResolveRepository<NextLiveShowRepository>())
            {
                string content = "";
                List<NextLiveShow> lst = repo.FindActive().ToList();
                foreach (NextLiveShow item in lst)
                {
                    content += string.Format("<div class=\"live_show_schedule\" style=\"display:none;\"><li><span>{0}</span>&nbsp;{1}&nbsp;{2}</li></div>", item.NextLiveShowName, item.NextLiveShowDate.ToString("d"), item.NextLiveShowDate.ToString("t"));
                }
                slider2.InnerHtml = content;
            }

        }

        private void SetActiveLink()
        {
            string namePage = Page.GetType().FullName;

            hlHome.Attributes["class"] = hlHome.Attributes["class"].Replace(" active", "");
            hlForum.Attributes["class"] = hlForum.Attributes["class"].Replace(" active", "");
            hlAudition.Attributes["class"] = hlAudition.Attributes["class"].Replace(" active", "");
                        
            /*hlMyVideos.Attributes["class"] = hlMyVideos.Attributes["class"].Replace(" active", "");
            hlMyPhotosets.Attributes["class"] = hlMyPhotosets.Attributes["class"].Replace(" active", "");
            hlFitness.Attributes["class"] = hlFitness.Attributes["class"].Replace(" active", "");*/
                        
            if (namePage == "ASP.home_aspx")
            {
                hlHome.Attributes["class"] += " active";
            }
            else if (namePage == "ASP.membersforum_aspx")
            {
                hlForum.Attributes["class"] += " active";
            }
            else if (namePage == "ASP.audition_aspx")
            {
                hlAudition.Attributes["class"] += " active";
            }

            /*else if (namePage == "ASP.pornstars_aspx")
            {
                hlPornStars.Attributes["class"] += " active";
            }
            else if (namePage == "ASP.aboutme_aspx")
            {
                hlAboutMe.Attributes["class"] += " active";
            }
            else if (namePage == "ASP.store_aspx")
            {
                hlStore.Attributes["class"] += " active";
            }
            else if (namePage == "ASP.membersforum_aspx")
            {
                hlMembersForum.Attributes["class"] += " active";
            }
            else if (namePage == "ASP.fitness_aspx")
            {
                hlFitness.Attributes["class"] += " active";
            }
            else if (namePage == "ASP.myvideos_aspx")
            {
                hlMyVideos.Attributes["class"] += " active";
            }
            else if (namePage == "ASP.myphotosets_aspx")
            {
                hlMyPhotosets.Attributes["class"] += " active";
            }*/
        }
    }
}